package com.newhero.sjzsw;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import net.sf.json.JSONObject;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class CommitTest {

	//获取组织机构信息
	public void  getOrgans (){
		
		String result = "";
		String url = "http://localhost:8089/sjzsw_web/docInfoService/getOrgans";
		String account = "admin";
		String password = "admin";
		String str="str={'account':'" + account + "','password':'" + password + "'}";
		CloseableHttpClient httpClient = HttpClients.createDefault();
        try {
        	
            StringEntity stringEntity = new StringEntity(str);
            HttpPost httpPost = new HttpPost(url);
            stringEntity.setContentEncoding("utf-8");
            stringEntity.setContentType("application/x-www-form-urlencoded");
            httpPost.setEntity(stringEntity);
            CloseableHttpResponse response = httpClient.execute(httpPost);
            try {
                HttpEntity entity = response.getEntity();
                
                if (entity != null) {
                    result = EntityUtils.toString(entity);
                    System.out.println("*********************************");
                    System.out.println("result=" + result);
                }
                               
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
	}
	
	//文件信息发送
	public void  docInfoSend (){
		
			String result = "";
			String url = "http://localhost:8089/sjzsw_web/docInfoService/docInfoSend";
			String account = "admin";
			String password = "admin";
			String ywid = "ywid";
			String ywextid = "ywextid";
			String ywtype = "0";
			String infokind = "infokind";
			String infotitle = "infotitle";
			String infofwjg = "infofwjg";
			String infoyear = "2019";
			String infojjcd = "infojjcd";
			String infolxr = "infolxr";
			String infolxdh = "infolxdh";
			String cuid = "cuid";
			String cuname = "cuname";
			String coid = "coid";
			String coname = "coname";
			String ctime = "ctime";
			String qrcode = "qrcode";
			String toid = "toid";
			String toname = "toname";
			
			String str="str={'account':'" + account + "','password':'" + password + "'" +
					",'ywid':'" + ywid + "','ywextid':'" + ywextid + "','ywtype':'" + ywtype + "','infokind':'" + infokind + "','infotitle':'" + infotitle + "','infofwjg':'" + infofwjg + "','infoyear':'" + infoyear + "','infojjcd':'" + infojjcd + "'" +
							",'infolxr':'" + infolxr + "','infolxdh':'" + infolxdh + "','cuid':'" + cuid + "','cuname':'" + cuname + "','coid':'" + coid + "','coname':'" + coname + "','ctime':'" + ctime + "','qrcode':'" + qrcode + "','toid':'" + toid + "'" +
									",'toname':'" + toname + "'}";
			CloseableHttpClient httpClient = HttpClients.createDefault();
	        try {
	        	
	            StringEntity stringEntity = new StringEntity(str);
	            HttpPost httpPost = new HttpPost(url);
	            stringEntity.setContentEncoding("utf-8");
	            stringEntity.setContentType("application/x-www-form-urlencoded");
	            httpPost.setEntity(stringEntity);
	            CloseableHttpResponse response = httpClient.execute(httpPost);
	            try {
	                HttpEntity entity = response.getEntity();
	                
	                if (entity != null) {
	                    result = EntityUtils.toString(entity);
	                    System.out.println("*********************************");
	                    System.out.println("result=" + result);
	                }
	                               
	            } finally {
	                response.close();
	            }
	        } catch (ClientProtocolException e) {
	            e.printStackTrace();
	        } catch (UnsupportedEncodingException e1) {
	            e1.printStackTrace();
	        } catch (IOException e) {
	            e.printStackTrace();
	        } finally {
	            // 关闭连接,释放资源
	            try {
	                httpClient.close();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
		}
	
	//办理过程接口
	public void  docInfoProcess(){
			
			String result = "";
			String url = "http://localhost:8089/sjzsw_web/docInfoService/docInfoProcess";
			String account = "admin";
			String password = "admin";
			String ywid = "ywid";
			String ywextid = "ywextid";
			String qrcode = "qrcode";
			String state = "1";
			String endtime = "endtime";
			String userid = "userid";
			String username = "username";
			String organid = "organid";
			String organname = "organname";
			String content = "content";
			
			
			String str="str={'account':'" + account + "','password':'" + password + "'" +
					",'ywid':'" + ywid + "','ywextid':'" + ywextid + "','qrcode':'" + qrcode + "','state':'" + state + "','endtime':'" + endtime + "','userid':'" + userid + "','username':'" + username + "','organid':'" + organid + "'" +
							",'organname':'" + organname + "','content':'" + content + "'}";
			CloseableHttpClient httpClient = HttpClients.createDefault();
	        try {
	        	
	            StringEntity stringEntity = new StringEntity(str);
	            HttpPost httpPost = new HttpPost(url);
	            stringEntity.setContentEncoding("utf-8");
	            stringEntity.setContentType("application/x-www-form-urlencoded");
	            httpPost.setEntity(stringEntity);
	            CloseableHttpResponse response = httpClient.execute(httpPost);
	            try {
	                HttpEntity entity = response.getEntity();
	                
	                if (entity != null) {
	                    result = EntityUtils.toString(entity);
	                    System.out.println("*********************************");
	                    System.out.println("result=" + result);
	                }
	                               
	            } finally {
	                response.close();
	            }
	        } catch (ClientProtocolException e) {
	            e.printStackTrace();
	        } catch (UnsupportedEncodingException e1) {
	            e1.printStackTrace();
	        } catch (IOException e) {
	            e.printStackTrace();
	        } finally {
	            // 关闭连接,释放资源
	            try {
	                httpClient.close();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
		}
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		CommitTest com = new CommitTest();
		com.getOrgans();
		com.docInfoSend();
		com.docInfoProcess();
	}

}
